/**
 * @file CPvmMasterCommands.cpp Implementácia triedy CPvmMasterCommands.
 *
 * @author Martin Kosorinský.
 * @date 10.10.2009.
 */

#include "CPvmMasterCommands.hpp"

void CPvmMasterCommands::pvmUnpackDistPoint(epoint * P, big a, big b) {

    big y[4];
    y[0] = mirvar(0);
    y[1] = mirvar(0);
    y[2] = mirvar(0);
    y[3] = mirvar(0);

    pvmUnpackBig(y, 4, 1);

    copy(y[2], a);
    copy(y[3], b);

    if (!epoint_set(y[0], y[1], 0, P)) {
        cerr << "Error: '" << __FUNCTION__ << "': Bod nelezi na krivke!" << endl;
        pvm_exit();
        exit(1);
    }

    mirkill(y[0]);
    mirkill(y[1]);
    mirkill(y[2]);
    mirkill(y[3]);
}

void CPvmMasterCommands::pvmSendECParams(int tid, big a, big b, big p, big o, epoint * g) {
    big x[6];
    x[4] = mirvar(0);
    x[5] = mirvar(0);

    x[0] = a;
    x[1] = b;
    x[2] = p;
    x[3] = o;
    epoint_get(g, x[4], x[5]);

    tracer << "Odosielam ECParams, adresat: t" << hex << tid << endl;

    pvm_initsend(PvmDataDefault);        // inicializaciaa send buffer
    pvmPackBig(x, 6, 1);
    pvm_send(tid, PVM_ECDLP_ECPARAMS);

    mirkill(x[4]);
    mirkill(x[5]);
}

void CPvmMasterCommands::pvmSendTaskPoint(int tid, epoint * P) {

    big x[2];
    x[0] = mirvar(1);
    x[1] = mirvar(1);

    epoint_get(P, x[0], x[1]);

    tracer << "Odosielam TaskPoint: " << P << ", adresat: t" << hex << tid << endl;

    pvm_initsend(PvmDataDefault);        // inicializaciaa send buffer
    pvmPackBig(x, 2, 1);
    pvm_send(tid, PVM_ECDLP_TASKPOINT);  // odoslana sprava pre TID s kodom PVM_ECDLP_DISTPOINT

    mirkill(x[0]);
    mirkill(x[1]);
}

void CPvmMasterCommands::pvmUnpackDL(big d) {
    pvmUnpackBig(&d, 1, 1);;
}
